package com.eks.order.controller;

import com.eks.order.api.OrderApi;
import com.eks.user.api.UserApi;
import com.eks.user.exception.UserNameException;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * OrderController
 *
 * @author: chenfenghai
 * @version: 1.0
 * @date: 2020-06-03 14:48
 * @blame Team
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderApi orderApi;

    @Reference(version = "1.0.0")
    UserApi userApi;

    @GetMapping("/test")
    public String test(){
        return "OrderController.test";
    }

    @ApiOperation(value = "订单", notes = "获取订单编码")
    @GetMapping("/getOrderCode")
    public String getOrderCode(){
        NetUtils.getHostAddress();
        return orderApi.getOrderCode();
    }

    @GetMapping("/getUserName")
    public String getUserName(@RequestParam(required = false) String id){
        try {
            return userApi.getUserName(id);
        }catch (Exception ex){
            if(ex instanceof UserNameException){
                System.out.println("UserNameException");
            }
            return ex.getMessage();
        }
    }
}
